package sms

import (
	httpUtil "app/pkg/http"
	"encoding/json"
)

const smsSignId = "2e65b1bb3d054466b82f0c9d125465e2"
const templateId = "908e94ccf08b4476ba6c876d13f084ad"
const smsUrl = "https://gyytz.market.alicloudapi.com/sms/smsSend"
const appcode = "e388788fc4af489092e79e931f1914ec"

type Res struct {
	Msg     string `json:"msg"`
	Smsid   string `json:"smsid"`
	Code    string `json:"code"`
	Balance string `json:"balance"`
}

func SendMsg(code string, mobile string) (reply Res, err error) {
	res, err := httpUtil.Post(smsUrl, map[string]string{
		"param":      "**code**:" + code + ",**minute**:3",
		"smsSignId":  smsSignId,
		"templateId": templateId,
		"mobile":     mobile,
	}, map[string]string{
		"Authorization": "APPCODE " + appcode,
	}, 5)
	if err != nil {
		return
	}
	err = json.Unmarshal(res, &reply)
	return
}
